<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Controller
 *
 * @author thanhdx
 */
class Controller {

    protected $action;
    protected $model;

    public function setAction($ac) {
        $this->action = $ac;
    }

    public function execute() {
        $method = $this->action . "Action";
        if (method_exists($this, $method)) {
            $this->$method();
        }
    }

    public function loadView($view, $vars=null) {
        if (is_array($vars) && count($vars) > 0)
            extract($vars, EXTR_PREFIX_SAME, "dxt");
        require_once VIEWS_DIR.'/'.$view.'/'.$this->action.'.tpl.php';
    }
    
    public function loadModel($model){
        require_once MODEL_DIR. ucfirst($model).'.php';
        $model_class = ucfirst($model).'Model';
        $this->model = new $model_class;
    }
    
    public function getModel($model){
        if(!$this->model){
            $this->loadModel($model);
        }
        return $this->model;
    }

}

?>
